//引入请求方法
import {request} from '../../request/index.js';
import regeneratorRuntime from '../../lib/runtime/runtime';


// pages/order/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabs:[
      {
        id:0,
        value:"全部",
        isActive:true,
      },
      {
        id:1,
        value:"待付款",
        isActive:false,
      },
      {
        id:2,
        value:"待发货",
        isActive:false,
      },
      {
        id:3,
        value:"退款/退货",
        isActive:false
      }
    ],
   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

//根据标题选中激活
  ChangeTitleByIndex(index){
    //修改源数组
    let {tabs} = this.data;
    tabs.forEach((v,i) => i===index?v.isActive=true:v.isActive=false);
    //赋值到data中
    this.setData({
      tabs
    })
  },
  //标题 点击事件，从子组件传递过来的
  handleTabsItemChange(e){
    //console.log(e);
    //获取被点击的标题索引
    const {index} = e.detail;
    this.ChangeTitleByIndex(index);
    //重新发送请求
    // this.ChangeTitleByIndex(index+1);
  },


  onShow(options){
    // const token = wx.getStorageSync("token");
    // if(!token){
    //   wx.navigateTo({
    //     url: '/pages/auth/index',
    //   });
    //   return;
    // }
      

    let pages =  getCurrentPages();
    let currentPage = pages[pages.length-1];
    //获取url上的参数
    const {type} = currentPage.options;
    //激活选中标题
    this.ChangeTitleByIndex(type-1);
    this.getOrders(type);
      
  },
  //获取列表订单的方法
  async getOrders(type){
    const res = await request({url:"https://api-hmugo-web.itheima.net/api/public/v1/my/orders/all",data:{type}});
    
  }
 
})